import Vue from 'vue'
import VueRouter from 'vue-router'
import mainVue from '@/views/main/index.vue'

Vue.use(VueRouter)

const routes = [{
    path: '/',
    component: mainVue,
    redirect: "/manage",
    children: [{
        path: 'manage',
        component: () =>
            import ('@/views/goods/manage')
    }, {
        path: 'warning',
        component: () =>
            import ('@/views/goods/warning')
    }, {
        path: 'pull-order',
        component: () =>
            import ('@/views/pull/order')
    }, {
        path: 'count',
        component: () =>
            import ('@/views/pull/count')
    }]
}, {
    path: '/login',
    name: 'login',
    component: () =>
        import ('@/views/login/index.vue')
}]

const router = new VueRouter({
    routes
})
router.beforeEach((to, from, next) => {
    let token = localStorage.getItem("token");
    //跳登录页是不需要进行token验证的
    if (to.name === 'login') {
        next();
    } else {
        if (token === '' || token === undefined || token === null) {
            next({ path: '/login' });
        } else {
            next();
        }
    }

})

export default router